﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.hylAffixFile.Attributes.Add("onclick", "openFileUpload(null, 'diary')");
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        User curLoginUser = (User)Session["user"];
        if (string.IsNullOrEmpty(this.txtDiaryTitle.Text.Trim()) || string.IsNullOrEmpty(this.txtDiaryContent.Text.Trim()))
        {
            UserDiarytbService userDiarytbService = new UserDiarytbService();
            string diaryTitle = this.txtDiaryTitle.Text.Trim();
            string diaryContent = this.txtDiaryContent.Text.Trim();

            if (string.IsNullOrEmpty(diaryTitle))
            {
                ScriptManager.RegisterClientScriptBlock(this.Page,this.GetType(),"","alert('主题不能为空')",true);
                return;
            }

            if (string.IsNullOrEmpty(diaryContent))
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('内容不能为空')", true);
                return;
            }
            int did = userDiarytbService.saveUserDiary(diaryTitle, curLoginUser.LoginName, diaryContent, DateTime.Now);
            if (this.uploadFilePaths.Value != null && !"".Equals(this.uploadFilePaths.Value))
            {
                string[] filePaths = this.uploadFilePaths.Value.Trim().Split(',');
                DiaryFileUploadMappingtbService diaryFileUploadMappingtbService = new DiaryFileUploadMappingtbService();
                for (int i = 0; i < filePaths.Length; i++)
                {
                    string fullFileName = filePaths[i].Substring(filePaths[i].LastIndexOf("\\") + 1);
                    string tempFileName = fullFileName.Substring(fullFileName.IndexOf("_") + 1);
                    string fileName = tempFileName.Substring(tempFileName.IndexOf("_") + 1);
                    diaryFileUploadMappingtbService.saveDiaryAffixFile(fileName, filePaths[i], DateTime.Now, did);
                }
            }
        }
        ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "window.parent.location.reload();", true);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link rel="Stylesheet" type="text/css" href="../../Styles/right_style.css" />
    <script type="text/javascript" src="../../js/MyOption.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.ui/js/jquery.js"></script>
    <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>
    <script type="text/javascript">
        function checkNewDiary() {
            var diaryTitle = $("#txtDiaryTitle");
            var diaryContent = $("#txtDiaryContent");

            var flag = true;

            if (diaryTitle.val() == '') {
                alert("主题不能为空");
                flag = false;
            }
            else if (diaryContent.val() == '') {
                alert("内容不能为空");
                flag = false;
            }

            return flag;
        }
    </script>
</head>
<body>
    <br />
    <form id="form1" runat="server">
    <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="dataList">
        <tr>
            <td colspan="2" align="center" height="30px">
                <font style="font-size: 12px">增加工作计划</font>
            </td>
        </tr>
        <tr>
            <td>
                主题:
            </td>
            <td align="left">
                <asp:TextBox ID="txtDiaryTitle" runat="server" Width="300px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td align="center">
                <font style="font-size: 12px">附件:</font>
            </td>
            <td align="left">
                <asp:ImageButton ID="hylAffixFile" runat="server" ImageUrl="~/images/fujian.gif" />
            </td>
        </tr>
        <tr>
            <td align="center">
                <font style="font-size: 12px">内容:</font>
            </td>
            <td align="left">
                <asp:TextBox ID="txtDiaryContent" runat="server" Height="156px" TextMode="MultiLine"
                    Width="500px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center" style="height: 27px">
                <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" OnClientClick="return checkNewDiary()"
                    Text="提交" Width="73px" />
                <input id="uploadFilePaths" runat="server" type="hidden" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
